/*初始化数据表格*/
function initTable() {
    var url=getBasePath()+'/mdm/questionnaireTask/getListData.json';
    var tableId="table_data";
    $("#"+tableId).dataTable().fnDestroy();
    json = {};
    json.showLineNuber = false;
    json.id = tableId;
    json.pagesize=10;
    json.url = url ;
    json.param = [
        {"name": "qtaskId", "value": $.trim($("#qtaskId").val())},
        {"name": "qnId", "value": $.trim($("#qnId").val())},
        {"name": "memberId", "value": $.trim($("#memberId").val())},
        {"name": "companyId", "value": $.trim($("#companyId").val())},
        {"name": "companyName", "value": $.trim($("#companyName").val())},
        {"name": "brandCode", "value": $.trim($("#brandCode").val())},
        {"name": "brandName", "value": $.trim($("#brandName").val())},
        {"name": "provinceCode", "value": $.trim($("#provinceCode").val())},
        {"name": "provinceName", "value": $.trim($("#provinceName").val())},
        {"name": "cityCode", "value": $.trim($("#cityCode").val())},
        {"name": "cityName", "value": $.trim($("#cityName").val())},
        {"name": "saleArea", "value": $.trim($("#saleArea").val())},
        {"name": "assignTime", "value": $.trim($("#assignTime").val())},
        {"name": "userName", "value": $.trim($("#userName").val())},
        {"name": "mobileNum", "value": $.trim($("#mobileNum").val())},
        {"name": "userJob", "value": $.trim($("#userJob").val())},
        {"name": "userJobTime", "value": $.trim($("#userJobTime").val())},
        {"name": "ifDone", "value": $.trim($("#ifDone").val())},
        {"name": "doneTime", "value": $.trim($("#doneTime").val())},
        {"name": "deleteMark", "value": $.trim($("#deleteMark").val())},
        {"name": "createUser", "value": $.trim($("#createUser").val())},
        {"name": "createTime", "value": $.trim($("#createTime").val())},
        {"name": "updateUser", "value": $.trim($("#updateUser").val())},
        {"name": "updateTime", "value": $.trim($("#updateTime").val())},
    ];
    json.columns = [
        {
            "mData": "questionnaireTaskCode", "sWidth": "15%", "sClass": "text-center",
            "mRender": function (data, type, row) {
                if (data) {
					var detailStr="<a class='icondatatable' vb='详情' href=\"#\" onclick='toDetailPage(\""+data+"\");'><i class=\"icon-detail\"></i></a>";
                    var editStr="<a class='icondatatable' vb='修改' href=\"#\" onclick='toEditQuestionnaireTask(\""+data+"\");'><i class=\"icon-edit\"></i></a>";
                    var delStr="<a class='icondatatable' vb='删除' href=\"#\"  onclick='deleteQuestionnaireTask(\""+data+"\");'><i class=\"icon-bin\"></i></a>";

                    return detailStr+editStr+delStr;
                }
            }
        },
        {"mData": "qtaskId", "sClass": "text-center"},
        {"mData": "qnId", "sClass": "text-center"},
        {"mData": "memberId", "sClass": "text-center"},
        {"mData": "companyId", "sClass": "text-center"},
        {"mData": "companyName", "sClass": "text-center"},
        {"mData": "brandCode", "sClass": "text-center"},
        {"mData": "brandName", "sClass": "text-center"},
        {"mData": "provinceCode", "sClass": "text-center"},
        {"mData": "provinceName", "sClass": "text-center"},
        {"mData": "cityCode", "sClass": "text-center"},
        {"mData": "cityName", "sClass": "text-center"},
        {"mData": "saleArea", "sClass": "text-center"},
        {"mData": "assignTime", "sClass": "text-center"},
        {"mData": "userName", "sClass": "text-center"},
        {"mData": "mobileNum", "sClass": "text-center"},
        {"mData": "userJob", "sClass": "text-center"},
        {"mData": "userJobTime", "sClass": "text-center"},
        {"mData": "ifDone", "sClass": "text-center"},
        {"mData": "doneTime", "sClass": "text-center"},
        {"mData": "deleteMark", "sClass": "text-center"},
        {"mData": "createUser", "sClass": "text-center"},
        {"mData": "createTime", "sClass": "text-center"},
        {"mData": "updateUser", "sClass": "text-center"},
        {"mData": "updateTime", "sClass": "text-center"},
    ];
    var oTable1 = TableManaged(json).init();
}
/*查询数据*/
function doQuery(){
    initTable();
}


/*重置查询条件*/
function resetQueryForm(){
	$("#qtaskId").val('');
	$("#qnId").val('');
	$("#memberId").val('');
	$("#companyId").val('');
	$("#companyName").val('');
	$("#brandCode").val('');
	$("#brandName").val('');
	$("#provinceCode").val('');
	$("#provinceName").val('');
	$("#cityCode").val('');
	$("#cityName").val('');
	$("#saleArea").val('');
	$("#assignTime").val('');
	$("#userName").val('');
	$("#mobileNum").val('');
	$("#userJob").val('');
	$("#userJobTime").val('');
	$("#ifDone").val('');
	$("#doneTime").val('');
	$("#deleteMark").val('');
	$("#createUser").val('');
	$("#createTime").val('');
	$("#updateUser").val('');
	$("#updateTime").val('');
}

/*删除数据*/
function deleteQuestionnaireTask(questionnaireTaskCode){
    var _url=getBasePath()+'/mdm/questionnaireTask/delete.json';
    $.Confirm('你确定要删除这条记录吗？','',function(){
        var questionnaireTask={};
        questionnaireTask.questionnaireTaskCode=questionnaireTaskCode;
        $.ajax({
            url:_url,
            type:'POST',
            dataType:'json',
            contentType:'application/json',
            data:JSON.stringify(questionnaireTask),
            success:function(data){
                if(data.status==200){
                    $.Success('删除成功',doQuery);
                }else{
                    var msg = data.message || "删除调查问卷任务数据发生错误";
                    $.Error(msg,'',null);
                }
            }
        });
    });

}

/*跳转编辑数据页面*/
function toEditQuestionnaireTask(questionnaireTaskCode){
    var _url=getBasePath()+'/mdm/questionnaireTask/toEdit.htm?questionnaireTaskCode='+questionnaireTaskCode;
    location.href=_url;
}

/*编辑数据*/
function editQuestionnaireTask(){
    $validator =$("#questionnaireTask_edit_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/questionnaireTask/edit.json';
    var questionnaireTask={};
	questionnaireTask.qtaskId=$("#qtaskId").val();
	questionnaireTask.qnId=$("#qnId").val();
	questionnaireTask.memberId=$("#memberId").val();
	questionnaireTask.companyId=$("#companyId").val();
	questionnaireTask.companyName=$("#companyName").val();
	questionnaireTask.brandCode=$("#brandCode").val();
	questionnaireTask.brandName=$("#brandName").val();
	questionnaireTask.provinceCode=$("#provinceCode").val();
	questionnaireTask.provinceName=$("#provinceName").val();
	questionnaireTask.cityCode=$("#cityCode").val();
	questionnaireTask.cityName=$("#cityName").val();
	questionnaireTask.saleArea=$("#saleArea").val();
	questionnaireTask.assignTime=$("#assignTime").val();
	questionnaireTask.userName=$("#userName").val();
	questionnaireTask.mobileNum=$("#mobileNum").val();
	questionnaireTask.userJob=$("#userJob").val();
	questionnaireTask.userJobTime=$("#userJobTime").val();
	questionnaireTask.ifDone=$("#ifDone").val();
	questionnaireTask.doneTime=$("#doneTime").val();
	questionnaireTask.deleteMark=$("#deleteMark").val();
	questionnaireTask.createUser=$("#createUser").val();
	questionnaireTask.createTime=$("#createTime").val();
	questionnaireTask.updateUser=$("#updateUser").val();
	questionnaireTask.updateTime=$("#updateTime").val();

    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(questionnaireTask),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "编辑调查问卷任务数据发生错误";
                $.Error(msg,'',null);
            }

        },
        error:function(data){
            JSON.stringify(data);
        }
    });
}

/* 跳转明细页面*/
function toDetailPage(code){
    var _url=getBasePath()+'/mdm/questionnaireTask/detail.htm?questionnaireTaskCode='+code;
    location.href=_url;
}
/*跳转新增数据页面*/
function toAddQuestionnaireTask(){
    var _url=getBasePath()+'/mdm/questionnaireTask/toAdd.htm';
    location.href=_url;
}

/*新增数据*/
function saveQuestionnaireTask(){
    $validator =$("#questionnaireTask_add_form").validator('isFormValid');
    if(!$validator){
        return;
    }
    var _url=getBasePath()+'/mdm/questionnaireTask/add.json';
    var questionnaireTask={};
	questionnaireTask.qtaskId=$("#qtaskId").val();
	questionnaireTask.qnId=$("#qnId").val();
	questionnaireTask.memberId=$("#memberId").val();
	questionnaireTask.companyId=$("#companyId").val();
	questionnaireTask.companyName=$("#companyName").val();
	questionnaireTask.brandCode=$("#brandCode").val();
	questionnaireTask.brandName=$("#brandName").val();
	questionnaireTask.provinceCode=$("#provinceCode").val();
	questionnaireTask.provinceName=$("#provinceName").val();
	questionnaireTask.cityCode=$("#cityCode").val();
	questionnaireTask.cityName=$("#cityName").val();
	questionnaireTask.saleArea=$("#saleArea").val();
	questionnaireTask.assignTime=$("#assignTime").val();
	questionnaireTask.userName=$("#userName").val();
	questionnaireTask.mobileNum=$("#mobileNum").val();
	questionnaireTask.userJob=$("#userJob").val();
	questionnaireTask.userJobTime=$("#userJobTime").val();
	questionnaireTask.ifDone=$("#ifDone").val();
	questionnaireTask.doneTime=$("#doneTime").val();
	questionnaireTask.deleteMark=$("#deleteMark").val();
	questionnaireTask.createUser=$("#createUser").val();
	questionnaireTask.createTime=$("#createTime").val();
	questionnaireTask.updateUser=$("#updateUser").val();
	questionnaireTask.updateTime=$("#updateTime").val();
    
    $.ajax({
        url:_url,
        type:'POST',
        dataType:'json',
        contentType:'application/json',
        data:JSON.stringify(questionnaireTask),
        success:function(data){
            if(data.status==200){
                $.Success('该记录已提交成功!',gotoListPage);
            }else{
                var msg = data.message || "新增调查问卷任务数据发生错误";
                $.Error(msg,'',null);
            }
        }
    });
}

/*跳转数据列表页面*/
function gotoListPage(){
    location.href=getBasePath()+'/mdm/questionnaireTask/list.htm';
}





